from rest_framework import serializers

from . import models


class BookModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Book
        fields = ['id', 'name', 'book_img', 'total_word_number', 'total_up_num',
                  'category_name', 'author_name',
                  'updated_time', 'current_status', 'article_list', 'desc', 'is_free', 'total_section']
        extra_kwargs = {
            'category_name': {'read_only': True},
            'author_name': {'read_only': True},
            'article_list': {'read_only': True},
            'current_status': {'read_only': True},
        }


class BookCategoryModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Category
        fields = ['id', 'name', 'book_list']
        extract_kwargs = {
            'book_list': {'read_only': True}
        }


class ArticleModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Article
        fields = ['id', 'title', 'content', 'word_number', 'up_num', 'current_section_name', 'current_section',
                  'is_free', 'updated_time']
